package com.ruoyi.web.controller.wechat;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.constant.UserType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.domain.vo.WxContentEntity;
import com.ruoyi.system.service.*;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *微信小程序接口
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/wechatzx")
public class WechatZxController extends BaseController
{
    @Autowired
    private ISysCardService sysCardService;
    @Autowired
    private ISysWxUserService sysWxUserService;
    @Autowired
    private ISysContentService sysContentService;
    @Autowired
    private ISysVipRulesService sysVipRulesService;
    @Autowired
    private ISysNoticeServiceService sysNoticeServiceService;
    @Autowired
    private ISysConfigService configService;//用于动态获取小程序加盟商信息
    @Autowired
    private ISysAboutmeService sysAboutmeService;
    @Autowired
    private ISysUserService userService;

    @Autowired
    private ISysZxCategoryService zxCategoryService;
    @Autowired
    private ISysZxContentService zxContentService;
    /**
     * 获取分类列表
     */
    @GetMapping(value = {"/{ownerid}/classList", "/classList"})
    public AjaxResult getClassList(HttpServletResponse response, @PathVariable(required = false) String ownerid) throws IOException
    {
        SysZxCategory sysZxCategory=new SysZxCategory();
        if (!StringUtils.isEmpty(ownerid)){
            sysZxCategory.setOwnerid(ownerid);
        }else {
            sysZxCategory.setOwnerid("1");
        }
        return AjaxResult.success(zxCategoryService.selectSysZxCategoryList(sysZxCategory));
    }


    /**
     * 获取商品详情
     */
    @GetMapping(value = {"/{ownerid}/articleDetail", "/articleDetail"})
    public AjaxResult getArticleDetail(Long contentid  , @PathVariable(required = false) String ownerid) throws IOException
    {
        SysZxContent sysContent= zxContentService.selectSysZxContentByContentid(contentid);
        Map<String, Object> dd= new HashMap<>();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        dd.put("noticeContent",sysContent.getContent());
        dd.put("creatDate",format.format(sysContent.getCreatedate()) );
        dd.put("title",sysContent.getTitle() );
        dd.put("type",sysContent.getContentType() );
        dd.put("level",sysContent.getLevel() );
        dd.put("contentPic",sysContent.getContentPic() );//获取图片
        return  AjaxResult.success(dd);
    }
    @GetMapping(value = {"/{ownerid}/list", "/list"})
    public TableDataInfo list(WxContentEntity wxContentEntity, @PathVariable(required = false) String ownerid)
    {
        SysZxContent sysZxContent=new SysZxContent();
        sysZxContent.setContentType(wxContentEntity.getContentType());
        startPage();
        List<SysZxContent> list = zxContentService.selectSysZxContentList(sysZxContent);
        TableDataInfo dataInfo=getDataTable(list);
        return dataInfo;
    }

}
